<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Core_Db_Collection extends Core_Collection {

	protected $_conn = null;
	
	protected $_select = null;

	public function __construct($conn = null) {
		$this->_conn = $conn;
		$this->_select = App::object('Core_Db_Select');
	}

	/**
	 * Prepare items for collection
	 */
	protected function _prepareData() {
		if (!$this->_items) {
			$query = $this->_conn->query((string)$this->_select);
			$this->_items = $query->result_array();
		}
		return $this;
	}
	
	public function getSelect() {
		return $this->_select;
	}
	
	public function setBaseTable($table) {
		$this->_select->from($table);
		$this->_select->columns($table.'.*');
	}
	
}